home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / hplip / copier / copier.pyc (.txt) < prev   
Python Compiled Bytecode  |  2009-10-28  |  9KB  |  197 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from __future__ import generators
  5. import sys
  6. import os
  7. import os.path as os
  8. import time
  9. import threading
  10. import Queue
  11. from cStringIO import StringIO
  12. from base.g import *
  13. from base.codes import *
  14. from base import device, utils, status, pml
  15. COPY_CANCELED = 1
  16. STATUS_IDLE = 0
  17. STATUS_SETTING_UP = 1
  18. STATUS_WARMING_UP = 2
  19. STATUS_ACTIVE = 3
  20. STATUS_DONE = 4
  21. STATUS_ERROR = 5
  22.  
  23. class PMLCopyDevice(device.Device):
  24.     
  25.     def __init__(self, device_uri = None, printer_name = None, service = None, callback = None):
  26.         device.Device.__init__(self, device_uri, printer_name, service, callback)
  27.         self.copy_thread = None
  28.  
  29.     
  30.     def copy(self, num_copies = 1, contrast = 0, reduction = 100, quality = pml.COPIER_QUALITY_NORMAL, fit_to_page = pml.COPIER_FIT_TO_PAGE_ENABLED, scan_style = SCAN_STYLE_FLATBED, update_queue = None, event_queue = None):
  31.         if not self.isCopyActive():
  32.             self.copy_thread = PMLCopyThread(self, num_copies, contrast, reduction, quality, fit_to_page, scan_style, update_queue, event_queue)
  33.             self.copy_thread.start()
  34.             return True
  35.         return False
  36.  
  37.     
  38.     def isCopyActive(self):
  39.         if self.copy_thread is not None:
  40.             return self.copy_thread.isAlive()
  41.         return False
  42.  
  43.     
  44.     def waitForCopyThread(self):
  45.         if self.copy_thread is not None and self.copy_thread.isAlive():
  46.             self.copy_thread.join()
  47.         
  48.  
  49.  
  50.  
  51. class PMLCopyThread(threading.Thread):
  52.     
  53.     def __init__(self, dev, num_copies, contrast, reduction, quality, fit_to_page, scan_style, update_queue = None, event_queue = None):
  54.         threading.Thread.__init__(self)
  55.         self.dev = dev
  56.         self.num_copies = num_copies
  57.         self.contrast = contrast
  58.         self.reduction = reduction
  59.         self.quality = quality
  60.         self.fit_to_page = fit_to_page
  61.         self.scan_style = scan_style
  62.         self.event_queue = event_queue
  63.         self.update_queue = update_queue
  64.         self.prev_update = ''
  65.         self.copy_type = self.dev.copy_type
  66.         log.debug('Copy-type = %d' % self.copy_type)
  67.  
  68.     
  69.     def run(self):
  70.         STATE_DONE = 0
  71.         STATE_ERROR = 5
  72.         STATE_ABORTED = 10
  73.         STATE_SUCCESS = 20
  74.         STATE_BUSY = 25
  75.         STATE_SET_TOKEN = 30
  76.         STATE_SETUP_STATE = 40
  77.         STATE_SETUP_PARAMS = 50
  78.         STATE_START = 60
  79.         STATE_ACTIVE = 70
  80.         STATE_RESET_TOKEN = 80
  81.         state = STATE_SETUP_STATE
  82.         while state != STATE_DONE:
  83.             if state == STATE_ABORTED:
  84.                 log.debug('%s State: Aborted' % '********************')
  85.                 self.write_queue(STATUS_DONE)
  86.                 state = STATE_RESET_TOKEN
  87.             
  88.             if state == STATE_ERROR:
  89.                 log.debug('%s State: Error' % '********************')
  90.                 self.write_queue(STATUS_ERROR)
  91.                 state = STATE_RESET_TOKEN
  92.                 continue
  93.             if state == STATE_SUCCESS:
  94.                 log.debug('%s State: Success' % '********************')
  95.                 self.write_queue(STATUS_DONE)
  96.                 state = STATE_RESET_TOKEN
  97.                 continue
  98.             None if state == STATE_BUSY else None if result_code > pml.ERROR_MAX_OK else check_token == token
  99.             if state == STATE_SETUP_STATE:
  100.                 log.debug('%s State: Setup state' % '********************')
  101.                 if self.copy_type == COPY_TYPE_DEVICE:
  102.                     (result_code, copy_state) = self.dev.getPML(pml.OID_COPIER_JOB)
  103.                     if copy_state == pml.COPIER_JOB_IDLE:
  104.                         self.dev.setPML(pml.OID_COPIER_JOB, pml.COPIER_JOB_SETUP)
  105.                         state = STATE_SETUP_PARAMS
  106.                     else:
  107.                         state = STATE_BUSY
  108.                 elif self.copy_type == COPY_TYPE_AIO_DEVICE:
  109.                     (result_code, copy_state) = self.dev.getPML(pml.OID_SCAN_TO_PRINTER)
  110.                     if copy_state == pml.SCAN_TO_PRINTER_IDLE:
  111.                         state = STATE_SETUP_PARAMS
  112.                     else:
  113.                         state = STATE_BUSY
  114.                 
  115.             self.copy_type == COPY_TYPE_DEVICE
  116.             if state == STATE_SETUP_PARAMS:
  117.                 log.debug('%s State: Setup Params' % '********************')
  118.                 if self.num_copies < 0:
  119.                     self.num_copies = 1
  120.                 
  121.                 if self.num_copies > 99:
  122.                     self.num_copies = 99
  123.                 
  124.                 if self.copy_type == COPY_TYPE_DEVICE:
  125.                     self.dev.setPML(pml.OID_COPIER_JOB_NUM_COPIES, self.num_copies)
  126.                     self.dev.setPML(pml.OID_COPIER_JOB_CONTRAST, self.contrast)
  127.                     self.dev.setPML(pml.OID_COPIER_JOB_REDUCTION, self.reduction)
  128.                     self.dev.setPML(pml.OID_COPIER_JOB_QUALITY, self.quality)
  129.                     if self.scan_style == SCAN_STYLE_FLATBED:
  130.                         self.dev.setPML(pml.OID_COPIER_JOB_FIT_TO_PAGE, self.fit_to_page)
  131.                     
  132.                 else:
  133.                     self.dev.setPML(pml.OID_COPIER_NUM_COPIES_AIO, self.num_copies)
  134.                     self.contrast = self.contrast * 10 / 25 + 50
  135.                     self.dev.setPML(pml.OID_COPIER_CONTRAST_AIO, self.contrast)
  136.                     if self.fit_to_page == pml.COPIER_FIT_TO_PAGE_ENABLED:
  137.                         self.reduction = 0
  138.                     
  139.                     self.dev.setPML(pml.OID_COPIER_REDUCTION_AIO, self.reduction)
  140.                     self.dev.setPML(pml.OID_COPIER_QUALITY_AIO, self.quality)
  141.                     self.dev.setPML(pml.OID_PIXEL_DATA_TYPE, pml.PIXEL_DATA_TYPE_COLOR_24_BIT)
  142.                     self.dev.setPML(pml.OID_COPIER_SPECIAL_FEATURES, pml.COPY_FEATURE_NONE)
  143.                     self.dev.setPML(pml.OID_COPIER_PHOTO_MODE, pml.ENHANCE_LIGHT_COLORS | pml.ENHANCE_TEXT)
  144.                     self.dev.setPML(pml.OID_COPIER_JOB_INPUT_TRAY_SELECT, pml.COPIER_JOB_INPUT_TRAY_1)
  145.                     self.dev.setPML(pml.OID_COPIER_MEDIA_TYPE, pml.COPIER_MEDIA_TYPE_AUTOMATIC)
  146.                     self.dev.setPML(pml.OID_PIXEL_DATA_TYPE, pml.PIXEL_DATA_TYPE_COLOR_24_BIT)
  147.                     self.dev.setPML(pml.OID_COPIER_SPECIAL_FEATURES, pml.COPY_FEATURE_NONE)
  148.                     self.dev.setPML(pml.OID_COPIER_JOB_MEDIA_SIZE, pml.COPIER_JOB_MEDIA_SIZE_US_LETTER)
  149.                 log.debug('num_copies = %d' % self.num_copies)
  150.                 log.debug('contrast= %d' % self.contrast)
  151.                 log.debug('reduction = %d' % self.reduction)
  152.                 log.debug('quality = %d' % self.quality)
  153.                 log.debug('fit_to_page = %d' % self.fit_to_page)
  154.                 state = STATE_START
  155.                 continue
  156.             None if state == STATE_START else self.copy_type == COPY_TYPE_DEVICE
  157.             if state == STATE_RESET_TOKEN:
  158.                 log.debug('%s State: Release copy token' % '********************')
  159.                 
  160.                 try:
  161.                     self.dev.setPML(pml.OID_COPIER_TOKEN, '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
  162.                 except Error:
  163.                     log.error('Unable to release copier token.')
  164.  
  165.                 self.dev.close()
  166.                 state = STATE_DONE
  167.                 continue
  168.  
  169.     
  170.     def check_for_cancel(self):
  171.         canceled = False
  172.         while self.event_queue.qsize():
  173.             
  174.             try:
  175.                 event = self.event_queue.get(0)
  176.                 if event == COPY_CANCELED:
  177.                     canceled = True
  178.                     log.debug('Cancel pressed!')
  179.             continue
  180.             except Queue.Empty:
  181.                 break
  182.                 continue
  183.             
  184.  
  185.             None<EXCEPTION MATCH>Queue.Empty
  186.         return canceled
  187.  
  188.     
  189.     def write_queue(self, message):
  190.         if self.update_queue is not None and message != self.prev_update:
  191.             self.update_queue.put(message)
  192.             time.sleep(0)
  193.             self.prev_update = message
  194.         
  195.  
  196.  
  197.